var oTable;
$(function() {
	
	$("form.form-search :button.btn-primary").click(function(e) {
				var data = AKF.formParams($("form.form-search"));
				oTable.gridSearch(data);
				e.preventDefault();
			});

	oTable = $('#membertable').initDT({
				"sAjaxSource" : "${_BASE_PATH}/system/member/query",
				"check" : "multi"
			});

	$("#newMemberBtn").click(function() {
				$.dialog({
							id : "newMemberDialog",
							url : "${_BASE_PATH}/static/system_member_newMember"
						});
			});

	$("#modifyMemberBtn").click(function() {

				if (oTable.getSelectedIds().length != 1) {
					$.alert("只能选择一个用户进行修改。");
					return;
				}
				$.dialog({
							id : "modifyMemberDialog",
							url : "${_BASE_PATH}/system/member/get",
							data : {
								id : oTable.getSelectedIds()[0]
							}
						});

			});

	$("#resetPasswordBtn").click(function() {

		if (oTable.getSelectedIds().length == 0) {
			$.alert("请选择要重置密码的用户");
			return;
		};

		$.confirm("您选择的用户的密码会被重置为666666，是否继续？", function() {
					$.ajax({
								url : "${_BASE_PATH}/system/member/resetPassword",
								data : {
									ids : oTable.getSelectedIds().toString()
								},
								success : function(result) {
									$.alert(result.msg);
								}
							});
				});
	});

	$("#lockMemberBtn").click(function() {

				if (oTable.getSelectedIds().length == 0) {
					$.alert("请选择要锁定的用户");
					return;
				};
				$.confirm("您选择的用户将会被锁定，锁定之后则不允许登录，是否继续？", function() {
							$.ajax({
										url : "${_BASE_PATH}/system/member/lockMember",
										data : {
											ids : oTable.getSelectedIds()
													.toString()
										},
										success : function(result) {
											$.alert(result.msg, function() {
														oTable.gridReload();
													});
										}
									});
						});
			});

	$("#unLockMemberBtn").click(function() {
				if (oTable.getSelectedIds().length == 0) {
					$.alert("请选择要解锁的用户");
					return;
				};
				$.ajax({
							url : "${_BASE_PATH}/system/member/unLockMember",
							data : {
								ids : oTable.getSelectedIds().toString()
							},
							success : function(result) {
								$.alert(result.msg, function() {
											oTable.gridReload();
										});
							}
						});
			});
	$("#selectall").click(function() {
				oTable.selectAllRow();
			});
	$("#cancelall").click(function() {
				oTable.unSelectAllRow();
			});

});